﻿using System;
using System.Collections.Generic;
using System.Linq;
using MaymuseMS.Models;
using MaymuseMS.Models.ValueObject;

namespace MaymuseMS.DAL {
    public class SupplierRepository : GenericRepository<Supplier> {
        public SupplierRepository(MaymuseMSContext context)
            : base(context) {}

        public IEnumerable<AutoCompleteModel> Get(string term) {
            return dbSet.Where(p => p.Name.Contains(term))
                .OrderByDescending(p=>p.SupplierId).Take(100)
                .Select(p => new AutoCompleteModel {
                    Id = p.SupplierId,
                    Name = p.Name,
                    Number = p.Number
                });
        }
    }
}